// Created by Windward Studios - no copyright is claimed. This code can be used in
// any manner by anyone for any reason. There is no copyright of any kind on it. You may
// use it in commercial products. You may change it without sharing those changes.
// We ask that you keep the "created by Windward Studios" in a comment at the top.

namespace net.windward.utils.ado
{
	/// <summary>
	/// This contains the parameters needed to create a connection string.
	/// </summary>
	public class WrConnectionParams
	{

		/// <summary>
		/// When a property is an int (as opposed to an Integer) this means it's value in the DB is null. 
		/// For a PK this means that the object is not stored in the DB yet.
		/// </summary>
		public const int NULL_PK = -1;

		private readonly string provider;
		private readonly string server;
		private readonly string database;
		private readonly WrCredentials credentials;

		/// <summary>
		/// Create a connection parameters object.
		/// </summary>
		/// <param name="provider">The name of the provider to connect with. Can be null.</param>
		/// <param name="server">The name of the server to connect to.</param>
		/// <param name="database">The name of the database to connect to. Can be null.</param>
		/// <param name="username">The username to use when connecting.</param>
		/// <param name="password">The password to use when connecting.</param>
		public WrConnectionParams(string provider, string server, string database, string username, string password)
		{
			this.provider = provider;
			this.server = server;
			this.database = database;
			credentials = new WrCredentials(username, password);
		}

		/// <summary>
		/// Create a connection parameters object.
		/// </summary>
		/// <param name="server">The name of the server to connect to.</param>
		/// <param name="database">The name of the database to connect to. Can be null.</param>
		/// <param name="username">The username to use when connecting.</param>
		/// <param name="password">The password to use when connecting.</param>
		public WrConnectionParams(string server, string database, string username, string password)
		{
			provider = null;
			this.server = server;
			this.database = database;
			credentials = new WrCredentials(username, password);
		}

		/// <summary>
		/// Create a connection parameters object using identity as the credentials.
		/// </summary>
		/// <param name="provider">The name of the provider to connect with. Can be null.</param>
		/// <param name="server">The name of the server to connect to.</param>
		/// <param name="database">The name of the database to connect to. Can be null.</param>
		public WrConnectionParams(string provider, string server, string database)
		{
			this.provider = provider;
			this.server = server;
			this.database = database;
			credentials = new WrCredentials();
		}

		/// <summary>
		/// Create a connection parameters object using identity as the credentials.
		/// </summary>
		/// <param name="server">The name of the server to connect to.</param>
		/// <param name="database">The name of the database to connect to. Can be null.</param>
		public WrConnectionParams(string server, string database)
		{
			provider = null;
			this.server = server;
			this.database = database;
			credentials = new WrCredentials();
		}

		/// <summary>
		/// Create a connection parameters object where we know nothing.
		/// </summary>
		public WrConnectionParams()
		{
			provider = server = database = null;
			credentials = new WrCredentials();
		}

		/// <summary>
		/// The name of the provider to connect with. Can be null.
		/// </summary>
		public string Provider
		{
			get { return provider; }
		}

		/// <summary>
		/// The name of the server to connect to.
		/// </summary>
		public string Server
		{
			get { return server; }
		}

		/// <summary>
		/// The name of the database to connect to. Can be null.
		/// </summary>
		public string Database
		{
			get { return database; }
		}

		/// <summary>
		/// The credentials to use when connecting.
		/// </summary>
		public WrCredentials Credentials
		{
			get { return credentials; }
		}
	}
}
